/**
 *@auther: tang
 *@Date: 2021-02-22
 *Project: p2pPlatformSys
 *Lang: TypeScript
 */
import { Controller } from 'egg';

class DictionaryController extends Controller {
  async loanUserAdd() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    const result = await ctx.service.bids.add(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '添加失败，服务器异常,请联系管理员',
      };
    });
    console.log(result);
    if (result.id) {
      ctx.body = {
        code: 200,
        msg: '添加成功',
        row: result,
      };
    } else {
      ctx.body = {
        code: 400,
        msg: '添加失败，服务器异常',
      };
    }
  }
  async loanUserUpdate() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    const result = await ctx.service.bids.update(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '修改失败，服务器异常',
      };
    });
    if (result[0] > 0) {
      ctx.body = {
        code: 200,
        msg: '修改成功',
      };
    } else {
      ctx.body = {
        code: 400,
        msg: '修改失败，服务器异常',
      };
    }
  }
  async loanUserList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.loanUserQuery(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      // utils.LogCals.success(ctx, '查询借款用户', 0);
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
  async fundsUsagesList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.fundsUsages(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
  async riskLevelsList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.riskLevels(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
  async repaymentMethodsList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.repaymentMethods(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
  async debitTypeList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.debitTypeList(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
  async guaranteeList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.guaranteeList(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
  async pledgeList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.pledgeList(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
  async addMoneyList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.addMoneyList(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
  async labelList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.labelList(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
  async categoryList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.categoryList(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
  async stateList() {
    const { ctx } = this;
    const prams:object[] = ctx.request.body;
    console.log(ctx.request);
    const result = await ctx.service.dictionary.stateList(prams).catch(() => {
      ctx.body = {
        code: 502,
        msg: '查询失败，服务器异常',
      };
    });
    if (result.length > 0) {
      ctx.helper.success(ctx, '查询成功', {
        row: result,
      });
    } else {
      ctx.helper.fail(ctx, {
        code: 400,
        msg: '查询失败，服务器异常',
      });
    }
  }
}

module.exports = DictionaryController;
